#

| Chapter 3 Customizing Your Environment |

## 3.3 Options

While aliases let you create convenient names for commands, they don't really let you change the shell's behavior. Options are one way of doing this. A shell option is a setting that is either "on" or "off." While several options relate to arcane shell features that are of interest only to programmers, those that we will cover here are of interest to all users.

The basic commands that relate to options are set -o optionnames and set +o optionnames, where optionnames is a list of option names separated by blanks. The use of plus (+) and minus (-) signs is counterintuitive: the - turns the named option on, while the + turns it off. The reason for this incongruity is that the dash (-) is the conventional UNIX way of specifying options to a command, while the use of + is an afterthought.

Most options also have one-letter abbreviations that can be used in lieu of the set -o command; for example, set -o noglob can be abbreviated set -f. These abbreviations are carry-overs from the Bourne shell. Like several other "extra" Korn shell features, they exist to ensure upward compatibility; otherwise, their use is not encouraged.

Table 3.1 lists the options that are useful to general UNIX users. All of them are off by default except as noted.

Table 3.1: Basic Shell Options
Option | Description
--- | ---
bgnice | Run background jobs at lower priority (on by default)
emacs | Enter emacs editing mode
ignoreeof | Don't allow use of `[CTRL-D]` to log off; require the exit command
markdirs | When expanding filename wildcards, append a slash (/) to directories
noclobber | Don't allow output redirection (>) to clobber an existing file
noglob | Don't expand filename wildcards like * and ? (wildcard expansion is sometimes called globbing)
nounset | Indicate an error when trying to use a variable that is undefined
trackall | Turn on alias tracking[6]
vi | Enter vi editing mode

> [6] Future releases will have alias tracking enabled at all times and won't support this option.

There are several other options (22 in all; Appendix B lists them). To check the status of an option, just type set -o. The Korn shell will print a list of all options along with their settings. There is no direct way to test a single option, but here is a simple shell function to do it:

>     function testopt {
>         if [[ -o $1 ]] ; then
>             print Option $1 is on.
>         else
>             print Option $1 is off.
>         fi
>     }

Shell functions will be covered in the next chapter. For now, though, if you want to use the testopt function, just type it into your .profile or environment file (see the section entitled "The Environment File"), then type either login or . .profile. Then you can type testopt optionname to check the status of an option.

3.2 Aliases |  | 3.4 Shell Variables